import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
//import store from './../store/index'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/Login',
  },
  {
    path: '/Login',
    name: 'Login',
    component: Login,
  },
  {
    path: '/Main',
    name: 'Main',
    component: ()=>import('../views/Main.vue'),
    meta: {
      isLogin: true,
      roles: ['admin'],
    },
    children:[
      {
        path: '/Main',
        redirect: '/Main/Home',
      },
      {
        path: '/Main/Home',
        name: 'Home',
        component: ()=>import('../views/Home.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],
        },
      },
      {
        path: '/Main/Order',
        name:'Order',
        component: ()=>import('../components/public/OrderNav.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],
        },
        children:[
          {
            path: '/Main/Order',
            redirect: '/Main/Order/PurchaseOrder',
          },
          {
            path: '/Main/Order/PurchaseOrder',
            name: 'PurchaseOrder',
            component: ()=>import('../views/order/PurchaseOrder.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
          {
            path: '/Main/Order/ReturnsOrder',
            name: 'ReturnsOrder',
            component: ()=>import('../views/order/ReturnsOrder.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
          {
            path: '/Main/Order/StatisticDelivery',
            name: 'StatisticDelivery',
            component: ()=>import('../views/order/StatisticDelivery.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
          {
            path: '/Main/Order/StatisticOrder',
            name: 'StatisticOrder',
            component: ()=>import('../views/order/StatisticOrder.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
        ]
      },
      {
        path: '/Main/Order/OrderDetails',
        name: 'OrderDetails',
        component: ()=>import('../views/order/OrderDetails.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],
        },
      },
      {
        path: '/Main/Order/ReOrderDetails',
        name: 'ReOrderDetails',
        component: ()=>import('../views/order/ReOrderDetails.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],
        },
      },
      {
        path: '/Main/Order/AddNewOrder',
        name: 'AddNewOrder',
        component: ()=>import('../views/order/AddNewOrder.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],
        },
      },
      {
        path: '/Main/Order/AddNewReOrder',
        name: 'AddNewReOrder',
        component: ()=>import('../views/order/AddNewReOrder.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],
        },
      },
      {
        path: '/Main/Goods',
        name:'Goods',
        component: ()=>import('../components/public/GoodsNav.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],
        },
        children:[
          {
            path: '/Main/Goods',
            redirect: '/Main/Goods/GoodsList',
          },
          {
            path: '/Main/Goods/GoodsList',
            name: 'GoodsList',
            component: ()=>import('../views/goods/GoodsList.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
          {
            path: '/Main/Goods/GoodsCollection',
            name: 'GoodsCollection',
            component: ()=>import('../views/goods/GoodsCollection.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
          {
            path: '/Main/Goods/GoodsCart',
            name: 'GoodsCart',
            component: ()=>import('../views/goods/GoodsCart.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
          {
            path: '/Main/Goods/GoodsDetails',
            name: 'GoodsDetails',
            component: ()=>import('../views/goods/GoodsDetails.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
        ]
      },
      {
        path: '/Main/Money',
        name:'Money',
        component: ()=>import('../components/public/MoneyNav.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],
        },
        children:[
          {
            path: '/Main/Money',
            redirect: '/Main/Money/CapitalAccount',
          },
          {
            path:  '/Main/Money/CapitalAccount',
            name: 'CapitalAccount',
            component: ()=>import('../views/money/CapitalAccount.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
          {
            path: '/Main/Money/PaymentDetails',
            name: 'PaymentDetails',
            component: ()=>import('../views/money/PaymentDetails.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
        ]
      },
      {
        path: '/Main/Promotion',
        name: 'Promotion',
        component: ()=>import('../views/promotion/Promotion.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],
        },
      },
      {
        path: '/Main/Notice',
        name: 'Notice',
        component: ()=>import('../views/notice/Notice.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],
        },
      },
      {
        path: '/Main/Message',
        name:'Message',
        component: ()=>import('../components/public/MessageNav.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],
        },
        children:[
          {
            path: '/Main/Message/ServiceMessage',
            name: 'ServiceMessage',
            component: ()=>import('../views/message/ServiceMessage.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
          {
            path:'/Main/Message/SystemNotice',
            name: 'SystemNotice',
            component: ()=>import('../views/message/SystemNotice.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
          {
            path: '/Main/Message/UpgradeAnnouncement',
            name: 'UpgradeAnnouncement',
            component: ()=>import('../views/message/UpgradeAnnouncement.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
        ]
      },
      {
        path: '/Main/MyAccount',
        name: 'MyAccount',
        component: ()=>import('../views/user/MyAccount.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],
        },
      },
      {
        path: '/Main/Set',
        name:'Set',
        component: ()=>import('../components/public/SetNav.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],
        },
        children:[
          {
            path: '/Main/Set/CompanyInformation',
            name: 'CompanyInformation',
            component: ()=>import('../views/set/CompanyInformation.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
          {
            path:'/Main/Set/OperationLog',
            name: 'OperationLog',
            component: ()=>import('../views/set/OperationLog.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
          {
            path: '/Main/Set/ReceivingInformation',
            name: 'ReceivingInformation',
            component: ()=>import('../views/set/ReceivingInformation.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
          {
            path: '/Main/Set/SharingSettings',
            name: 'SharingSettings',
            component: ()=>import('../views/set/SharingSettings.vue'),
            meta: {
              isLogin: true,
              roles: ['admin'],
            },
          },
        ]
      },
      {
        path: '/Main/Feedback',
        name:'Feedback',
        //component: ()=>import('../components/public/SetNav.vue'),
        meta: {
          isLogin: true,
          roles: ['admin'],
        },
      }
    ]
  },
];

const router = new VueRouter({
  routes
})
// router.beforeEach((to,from,next)=>{
//   //console.log(to.meta.isLogin)
//   if(to.meta.isLogin){
//     //需要登录
//     //判断系统是否登录
//     if(store.state.user.userName){
//       //为true，代表登陆了
//       //console.log(String(store.state.user.power))
//       //判断身份是否符合权限
//       //console.log(to.meta.roles)
//       //console.log(to.meta.roles.indexOf(String(store.state.user.power)))
//       if(to.meta.roles.indexOf(String(store.state.user.power)) >= 0){
//         next()
//       }else {
//         alert('您没有权限进入页面！')
//         router.push('/login')
//       }
//     }else {
//       alert('请登录之后再操作！')
//       router.push('/login')
//     }
//   }else {
//     next()
//   }
// })
export default router
